#!/usr/bin/env python
#-------------------------------python-----------------------luoghi.py--#
#                                                                       #
#                    Luoghi geometrici: coniche                         #
#                                                                       #
#--Bruno Stecca - Daniele Zambelli--------------------------------2003--#

from pyturtle import Turtle
from math import pi

class Geometra(Turtle):

  def conica1(self, raggio, p):
    numpassi=72
    lato=raggio*2*pi/numpassi
    ang=180./numpassi
    self.up(); self. forward(raggio); self.left(90); self.down()
    for i in range(numpassi):
      self.asse(p)
      self.left(ang); self.forward(lato); self.left(ang)

  def conica2(self, p):
    numpassi=80
    lato=5
    self.up(); self.back(200); self.down()
    for i in range(numpassi):
      self.asse(p)
      self.forward(lato)

  def asse(self, punto):
    dir=self.getdir()
    pos=self.getpos()
    self.up()
    self.lookat(punto)
    self.forward(self.distance(punto)/2.)
    self.left(90); self.back(1000)
    self.down(); self.forward(2000); self.up()
    self.setpos(pos); self.setdir(dir)
    self.down()

ell=Geometra()
ell.conica1(200, (150, 0))
para=Geometra()
para.conica2((0, 50))
iper=Geometra()
iper.conica1(100, (150, 0))
